package com.doremi.presentation.activities;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;

import com.doremi.R;
import com.doremi.service.ServiceLayer;
import com.doremi.service.impl.ServiceLayerImpl;
import com.doremi.util.Album;
import com.doremi.util.Track;

public class TracksMenuActivity extends Activity {
	
	/*private Button playListButton;
	private OnClickListener playListOnClickListener=new OnClickListener() {
		
		public void onClick(View v) {
			TrackQueque trackQueque=TrackQueque.instance();
			trackQueque.play(TracksMenuActivity.this);
			
			
		}
	};*/
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list_tracks);
		// obtengo el nombre del album seleccionado
		Bundle b = getIntent().getExtras();
		String artistString = b.getString("artist");
		String albumString = b.getString("album");
		
		//seteo el titulo de la actividad
		final TextView titleTracksListTextView = (TextView) findViewById(R.id.titleTracksListTextView);
		titleTracksListTextView.setText("Tracks de:"+albumString);

		//obtengo los sevicios 
		ServiceLayer serviceLayerImpl =ServiceLayerImpl.serviceLayerInstance;
		//obtengo todos los tracks el album y el artista seleccionado
		final ArrayList<Track> trackList = (ArrayList<Track>) serviceLayerImpl.getAllTracks(new Album(0, albumString, artistString));
		
		//obtengo la listView de tracks
		final ListView listview = (ListView) findViewById(R.id.tracksListView);

		//convieto la lista de tracks en una lista de strings para el aarayAdapter
		final ArrayList<String> list = new ArrayList<String>();
		for (int i = 0; i < trackList.size(); ++i) {
			list.add(trackList.get(i).getName());
			
		}
		//inicializao el arrayAdapter que permite listar los tracks
		//junto con un boton que agrega a una lista de reproduccion -> ver "TracksToAddArrayAdapter"
		final TracksToAddArrayAdapter adapter = new TracksToAddArrayAdapter(this,list,trackList);
		listview.setAdapter(adapter);
		
	
		
/*		//agrego el listener al boton PlayList
		this.playListButton=(Button)findViewById(R.id.playListButton);
		this.playListButton.setOnClickListener(this.playListOnClickListener);
	*/	
	      
	}
	@Override
	public void onDestroy()
	{
		super.onDestroy();

		
		
		
	}

}
